(原)
这个接口主要用于判断,先看看它的实现,说明,再给个例子。
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package java.util.function;
import java.util.Objects;
/**
* Represents a predicate (boolean-valued function) of one argument.
* 根据一个参数代表了一个基于boolean类型的断言
* This is a functional interface
* whose functional method is {@link #test(Object)}.
*这是一个函数式接口,它的函数方法是test
* @param the type of the input to the predicate
*根据输入类型得到一个断言
* @since 1.8
*/
@FunctionalInterface
public interface Predicate {
/**
* Evaluates this predicate on the given argument.
*根据给定的参数获得判断的结果
* @param t the input argument
* @return {@code true} if the input argument matches the predicate,
* otherwise {@code false}
*/
boolean test(T t);
/**
* Returns a composed predicate that represents a short-circuiting logical
* AND of this predicate and another. When evaluating the composed
* predicate, if this predicate is {@code false}, then the {@code other}
* predicate is not evaluated.
* 通过这个predicate和它的参数predicate 返回一个逻辑与的判断结果,
*当去计算这个复合的predicate时,如果当前的predicate 结果是false,那么就不会计算它的参数other的值。
* Any exceptions thrown during evaluation of either predicate are relayed
* to the caller; if evaluation of this predicate throws an exception, the
* {@code other} predicate will not be evaluated.
*如果这二个其中任何一个抛出异常,具体的处理交给调用的人,如果抛出了异常,它将不会被执行。
* @param other a predicate that will be logically-ANDed with this
* predicate
* @return a composed predicate that represents the short-circuiting logical
* AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/
default Predicate and(Predicate |